start pdb from within a script:
import pdb;pdb.set_trace()
start pdb from the commandline:
python -m pdb<file.py>
| Command | Description | 
|---|---|
| h(elp) | print available commands | 
| h(elp) command | print help about command | 
| q(uit) | quit debugger | 
| p(rint) expr | print value of expr | 
| pp expr | pretty print expr | 
| w(here) | print current position (inlcuding stack trace | 
| l(ist) | list 11 lines of code around the current line | 
| a(rgs) | print args of the current function | 
| n(ext) | execute the current statement step over | 
| s(tep) | execute and step into function | 
| r(eturn) | continue execution until the current function returns | 
| c(ontinue) | continue execution until a breakpoint is encountered | 
| u(p) | move one level up in stack trace | 
| d(own) | move one level down in stack trace | 
| b(reak) | show all breakpoints | 
| b(reak) lineno | set a breakpoint at lineno | 
| b(reak) func | set a breakpoint at the first line of a func | 
| !stmt | treat stmt as a Python statment instead of a pdb command | 
| exit | like exit debugger | 
In [1]:
    
%pdb on
    
    
In [1]:
    
%pdb
def pick_and_take():
    picked = numpy.random.randint(0, 1000)
    raise NotImplementedError()
pick_and_take()
    
    
    
    
    
In [3]:
    
import pdb;pdb.set_trace()
def func(x):
  return x + 1
for i in range(100):
  print(func(i))
  if i == 10 or i == 20:
    import pdb;pdb.set_trace()
raise Exception
    
    
    
In [1]:
    
def test_debug(y):
    x = 10
    # One-liner to start the debugger here.
    from IPython.core.debugger import Tracer; Tracer()()
    x = x + y
 
    for i in range(10):
        x = x+i
 
    return x
 
test_debug(10)
    
    
    
In [ ]:
    
from IPython import embed; embed()
    
    
In [1]:
    
import pixiedust
    
    
    
In [2]:
    
%%pixie_debugger
import random
def find_max (values):
    max = 0
    for val in values:
        if val > max:
            max = val
    return max
find_max(random.sample(range(100), 10))